﻿package mortal.game.view.copy.uniqueBoss.view
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.*;

    public class UniqueBossTimePanel extends CopyInfoPanelBase
    {
        private var _bgImg:GImageBitmap;
        private var _avatar:GImageBitmap;
        private var _name:GTextFiled;
        private var _combat:BitmapNumberText;
        protected var _minTxt:BitmapNumberText;
        protected var _secTxt:BitmapNumberText;
        protected var _timeTxt:BitmapNumberText;
        protected var _secView:SecTimerView;
        private var _rewardList:Vector.<BaseItem>;
        private var _sUniqueBossCopyInfo:SUniqueBossCopyInfoMsg;
        private static var _instance:UniqueBossTimePanel;

        public function UniqueBossTimePanel()
        {
            this._rewardList = new Vector.<BaseItem>;
            super(ImagesConst.copyInfoPanelTitle_UniqueBoss, 251);
            if (_instance != null)
            {
                throw new Error(" UniqueBossTimePanel 单例 ");
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            _bodySprite.x = 11;
            _bodySprite.y = 13;
            this._bgImg = UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTimerBg_, -11, -13, _bodySprite);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxt_1, 8, 211, _bodySprite));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxt_4, 8, 260, _bodySprite));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ChallengeNewSugCombatBg, 20, 162, _bodySprite));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxt_2, 84, 3, _bodySprite));
            var _loc_1:* = GlobalStyle.textFormatHuang2.center();
            _loc_1.size = 14;
            this._name = UIFactory.gTextField("", -11, 38, 251, 25, _bodySprite, _loc_1);
            this._avatar = UIFactory.gImageBitmap("", 85, 80, _bodySprite);
            this._combat = UIFactory.bitmapNumberText(105, 165, "SignUpNum2.png", 22, 23, -6, _bodySprite);
            this._minTxt = UIFactory.bitmapNumberText(20, 295, "ChallengeTimerNum.png", 35, 48, 0, null, 10);
            this._timeTxt = UIFactory.bitmapNumberText(30, 295, "ChallengeTimerNum.png", 35, 48, 0, _bodySprite, 10);
            this._secTxt = UIFactory.bitmapNumberText(160, 295, "ChallengeTimerNum.png", 35, 48, 0, null, 10);
            this._secView = UIFactory.secTimeView("", 0, 0, 0, 0, null);
            this._secView.configEventListener(EventName.SecViewTimeChange, this.onTimeChangeHd);
            return;
        }// end function

        private function updateRewardList() : void
        {
            var _loc_2:int = 0;
            this.removeRewardItems();
            var _loc_1:* = UICompomentPool.getUICompoment(BaseItem);
            _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            var _loc_3:Boolean = false;
            _loc_1.isDropAble = false;
            _loc_1.isDragAble = _loc_3;
            _loc_1.isShowLock = true;
            _loc_1.itemCode = int(CopyConfig.instance.getCopyInfoByCode(GameConst.UniqueBossCopyCode).rewardShow);
            _bodySprite.addChild(_loc_1);
            this._rewardList.push(_loc_1);
            _loc_2 = 0;
            while (_loc_2 < this._rewardList.length)
            {
                
                this._rewardList[_loc_2].x = _loc_2 * 45 + (265 - 45 * this._rewardList.length) * 0.5;
                this._rewardList[_loc_2].y = 206;
                _loc_2++;
            }
            return;
        }// end function

        private function removeRewardItems() : void
        {
            var _loc_1:BaseItem = null;
            for each (_loc_1 in this._rewardList)
            {
                
                _loc_1.dispose(true);
            }
            this._rewardList.length = 0;
            return;
        }// end function

        private function onTimeChangeHd(event:DataEvent) : void
        {
            if (this._secView == null)
            {
                return;
            }
            if (this._secView.secTimerViewData == null)
            {
                this._secView.stop();
                return;
            }
            var _loc_2:* = this._secView.secTimerViewData.mm();
            var _loc_3:* = this._secView.secTimerViewData.ss();
            this._timeTxt.text = _loc_2 + "(" + _loc_3;
            return;
        }// end function

        protected function setTimeCountDown() : void
        {
            var _loc_1:* = this._sUniqueBossCopyInfo.seconds;
            this._secView.stop();
            if (_loc_1 < 0)
            {
                return;
            }
            this._secView.setLeftTime(_loc_1);
            return;
        }// end function

        public function stopCount() : void
        {
            if (this._secView)
            {
                this._secView.stop();
            }
            return;
        }// end function

        public function set data(param1:SUniqueBossCopyInfoMsg) : void
        {
            var _loc_2:TBoss = null;
            var _loc_3:TCopy = null;
            this._sUniqueBossCopyInfo = param1;
            if (this._sUniqueBossCopyInfo)
            {
                _loc_2 = BossConfig.instance.getInfoByCode(GameConst.UniqueBossCode);
                if (_loc_2)
                {
                    this._avatar.imgUrl = _loc_2.avatarId + ".png";
                }
                _loc_3 = CopyConfig.instance.getCopyInfoByCode(this._sUniqueBossCopyInfo.copyCode);
                this._name.text = _loc_3 ? (_loc_3.name) : ("");
                this._combat.text = _loc_3 ? (_loc_3.combat.toString()) : ("");
            }
            this.updateRewardList();
            this.setTimeCountDown();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bgImg.dispose(param1);
            this._bgImg = null;
            this._name.dispose(param1);
            this._name = null;
            this._avatar.dispose(param1);
            this._avatar = null;
            this._timeTxt.dispose(param1);
            this._timeTxt = null;
            this._minTxt.dispose(param1);
            this._minTxt = null;
            this._secTxt.dispose(param1);
            this._secTxt = null;
            this._combat.dispose(param1);
            this._combat = null;
            this._secView.stop();
            this._secView.dispose();
            this._secView = null;
            this.removeRewardItems();
            this._sUniqueBossCopyInfo = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public static function get instance() : UniqueBossTimePanel
        {
            if (_instance == null)
            {
                _instance = new UniqueBossTimePanel;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
